/**
 *选关界面
*/
cc.Class({
    extends: cc.Component,

    properties: {
        levelSmall: cc.Prefab,
        levelBig: cc.Prefab,

    },

    onLoad() {
        this.index = 0;
        this.bgColor = [cc.Color.CYAN, cc.Color.YELLOW, cc.Color.MAGENTA]
        this.stageNode = this.node.getChildByName("stage_node");
        this.init();

    },

    start() {

        for (let i = 0; i < 3; i += 1) {
            this.stageNode.children[i].active = true;
        }
    },
    init() {
        let ran = Math.random() * 3 | 0;
        for (let i = 0; i < 12; i += 1) {
            let level_S = cc.instantiate(this.levelSmall);
            level_S.x = -220 + (i % 3) * 220;
            level_S.color = this.bgColor[ran];
            cc.loader.loadRes("label/label_" + parseInt(i + 1), cc.SpriteFrame, (err, frame) => {
                if (err) {
                    cc.log(err);
                }
                level_S.getChildByName("label").getComponent(cc.Sprite).spriteFrame = frame;

            })
            this.stageNode.addChild(level_S);

        }
        this.btnColor(this.bgColor[ran]);
    },
    btnColor(c) {
        this.node.getChildByName('cup_btn').color = c;
        this.node.getChildByName('setting_btn').color = c;
        this.node.getChildByName('ranking_btn').color = c;
        this.node.getChildByName('back_btn').color = c;
        this.node.getChildByName('star_btn').color = c;
    },
    changePage(event, customData) {
        for (let j = 0; j < 3; j += 1) {
            this.stageNode.children[this.index + j].active = false;
            this.stageNode.children[this.index + 3 * customData + j].active = true;

        }
        this.index = this.index + 3 * customData;
        if (this.index === 0) {
            this.node.getChildByName('prePage_btn').active = false;
        } else {
            this.node.getChildByName('prePage_btn').active = true;
        }
        if (this.index === 9) {
            this.node.getChildByName('nextPage_btn').active = false;
        } else {
            this.node.getChildByName('nextPage_btn').active = true;
        }
        let ran = Math.random() * 3 | 0;
        for (let i = 0; i < 12; i += 1) {
            this.stageNode.children[i].color = this.bgColor[ran]
        }
        this.btnColor(this.bgColor[ran]);
    },

    // update (dt) {},
});
